package com.zhang.service.impl;

import com.zhang.dao.RedisuserMapper;
import com.zhang.entity.Redisuser;
import com.zhang.entity.RedisuserExample;
import com.zhang.service.IUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * @author zhang
 * @time 2022/01/24 20:55:46
 */
@Service
@Transactional
public class UserServiceImpl implements IUserService {
    @Autowired
    private RedisuserMapper redisuserMapper;
    @Override
    public void save(Redisuser user) {
        redisuserMapper.insert(user);

    }

    @Override
    public Redisuser login(String username, String password) {
        RedisuserExample rue = new RedisuserExample();
        rue.or().andUsernameEqualTo(username).andPasswordEqualTo(password);
        List<Redisuser> userList = redisuserMapper.selectByExample(rue);
        return userList.size() > 0 ? userList.get(0) : null;
    }
}
